package com.phaeton.beemeup.updatehandlers;

import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.sprite.Sprite;

import com.phaeton.beemeup.GameManager;
import com.phaeton.beemeup.entity.IComb;

public class BeeHandler extends IHandler {

	public BeeHandler(GameManager gameManager) {
		super(gameManager);
	}

	@Override
	public void init() {		
		mGameManager.getLevel().registerUpdateHandler(new IUpdateHandler() {
			public void onUpdate(float pSecondsElapsed) {
				switch(mGameManager.getBeeCombs().size()){
					case 1:	case 2:	case 3: mGameManager.setMaxBees(1); break;
					case 4: case 5: case 6: mGameManager.setMaxBees(2); break;
					case 7: case 8: case 9: mGameManager.setMaxBees(3); break;
					case 10: case 11: case 12: mGameManager.setMaxBees(4); break;
					case 13: case 14: case 15: mGameManager.setMaxBees(5); break;
					default: mGameManager.setMaxBees(6); break;
				}
				if(mGameManager.getBees().size() < mGameManager.getMaxBees() && !mGameManager.getItemBar().getSlotActive(6) && (mGameManager.getHomeComb().getState() & IComb.OCCUPIED) == 0){
					mGameManager.getItemBar().setSlot(6, new Sprite(0,0,mGameManager.getActivity().getSceneManager().getTexture("SpawnBee"), mGameManager.getActivity().getVertexBufferObjectManager()));
					mGameManager.getItemBar().setSlotActive(6, true);
				}
				if(mGameManager.getBees().size() >= mGameManager.getMaxBees() && mGameManager.getItemBar().getSlotActive(6)){
					mGameManager.getItemBar().setSlot(6, new Sprite(0,0,mGameManager.getActivity().getSceneManager().getTexture("SpawnBeeDeactivated"), mGameManager.getActivity().getVertexBufferObjectManager()));
					mGameManager.getItemBar().setSlotActive(6, false);
				}
				if(mGameManager.getItemBar().getSlotActive(6) && (mGameManager.getHomeComb().getState() & IComb.OCCUPIED) == IComb.OCCUPIED){
					mGameManager.getItemBar().setSlot(6, new Sprite(0,0,mGameManager.getActivity().getSceneManager().getTexture("SpawnBeeDeactivated"), mGameManager.getActivity().getVertexBufferObjectManager()));
					mGameManager.getItemBar().setSlotActive(6, false);
				}
			}

			public void reset() {
			}
          });
	}

}
